﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy.Common;

namespace CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy
{
    public partial class ListaDemandasRemedy : System.Web.UI.Page
    {
        private AppCache appCache = new AppCache();
        private DataView odvChamados = new DataView();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                odvChamados.Table = appCache.Tb_ChamadosAbertos();
                odvChamados.RowFilter = "Area_Designada = 'DO-CVSA-DEMANDAS'";

                gvChamadosRemedy.DataSource = odvChamados;
                gvChamadosRemedy.DataBind();
                ltlQtdChamados.Text = odvChamados.Count.ToString();

            }
        }

        protected void btnPesquisar_Click(object sender, EventArgs e)
        {
            odvChamados.Table = appCache.Tb_ChamadosAbertos();
            odvChamados.RowFilter = "Area_Designada = 'DO-CVSA-DEMANDAS' ";
            odvChamados.RowFilter += " AND Empresa Like '%" + txtNomeCorretora.Text + "%'";
            if (!String.IsNullOrEmpty(txtIdIncidente.Text))
            {
                odvChamados.RowFilter += " And IdIncidente Like '%" + txtIdIncidente.Text + "%'";
            }
            gvChamadosRemedy.DataSource = odvChamados;
            gvChamadosRemedy.DataBind();
            ltlQtdChamados.Text = odvChamados.Count.ToString();
        }

        public string FormatarTexto(string texto)
        {
            texto = texto.Replace("\n", "<br />");
            return texto;
        }

        protected void formatRow(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                HtmlAnchor href = (HtmlAnchor)e.Row.FindControl("showDetail");
                HtmlGenericControl div = (HtmlGenericControl)e.Row.FindControl("div_txt");
                href.Attributes.Add("onclick", "javascript:showDetail(" + div.ClientID + ")");
                href.HRef = "#" + href.ClientID;
            }
        }
    }
}
